package com.example.joke.select

import android.database.Cursor
import android.os.Bundle
import androidx.loader.app.LoaderManager
import androidx.loader.content.Loader
import com.example.joke.base.navigationbar.AbsNavigationBar
import com.example.joke.databinding.ActivitySelectImageBinding
import com.example.joke.frame.BaseSkinActivity
import com.example.joke.frame.DefaultNavigationBar
const val EXTRA_SELECT_COUNT = "extra_select_count"
const val EXTRA_SELECT_MODE = "extra_select_mode"
const val EXTRA_DEFAULT_SELECT_LIST = "extra_default_select_list"
const val EXTRA_SHOW_CAMERA = "extra_show_camera"
const val MODE_MULTI = 0x0011
const val MODE_SINGLE = 0x0012
class SelectImageActivity : BaseSkinActivity<ActivitySelectImageBinding>() {


    private var mResultList: ArrayList<String>? = null
    private var mShowCamera: Boolean = true
    private var mMaxCount: Int = 9
    private var mMode: Int = MODE_MULTI

    override fun setListener() {
    }


    override fun initData() {
        val intent = intent
        mMode = intent.getIntExtra(EXTRA_SELECT_MODE, mMode)
        mMaxCount = intent.getIntExtra(EXTRA_SELECT_COUNT, mMaxCount)
        mShowCamera = intent.getBooleanExtra(EXTRA_SHOW_CAMERA, mShowCamera)
        mResultList = intent.getStringArrayExtra(EXTRA_DEFAULT_SELECT_LIST) as ArrayList<String>

        if (mResultList == null) {
            mResultList = ArrayList()
        }

        initImageList()
    }

    private val mLoadCallback = object : LoaderManager.LoaderCallbacks<Cursor> {
        override fun onCreateLoader(id: Int, args: Bundle?): Loader<Cursor> {
            TODO("Not yet implemented")
        }

        override fun onLoaderReset(loader: Loader<Cursor>) {
        }

        override fun onLoadFinished(loader: Loader<Cursor>, data: Cursor?) {
        }

    }

    // ContentProvider获取内存卡中所有的图片
    private fun initImageList() {
        // 耗时操作，开线程，asynctask
//        loaderManager.initLoader(0, null, mLoadCallback)
    }



    override fun initTitle() {
        DefaultNavigationBar.Builder(this)
            .setTitle("所有图片")
            .builder<AbsNavigationBar.Builder.AbsNavigationParams>()
    }

    override fun getBinding1(): ActivitySelectImageBinding {
        return ActivitySelectImageBinding.inflate(layoutInflater)
    }
}